package com.zch.socket.aio.server2;

import java.net.InetSocketAddress;
import java.nio.channels.AsynchronousServerSocketChannel;

public class Server {
    private int port;
    public static int clientCount=0;//客户端的连接数
    public Server(int port) {
        this.port = port;
    }

    public void start(){
        try{
            AsynchronousServerSocketChannel serverSocketChannel=AsynchronousServerSocketChannel.open().bind(new InetSocketAddress(port));
            System.out.println("服务器已启动，端口号：" + port);

            serverSocketChannel.accept(this,new ServerAcceptHandler());
            //保持服务端应用程序不关闭。
            while (true){

            }

        }catch (Exception e){
           e.printStackTrace();
        }
    }
}
